home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / DYNMEM.C < prev    next >
Text File  |  1994-07-22  |  2KB  |  84 lines

  1. /*
  2.  
  3.     Dynmem class definition for GCOOPE10 ported from PCOOPE21
  4.  
  5.       released as PUBLIC DOMAIN 4/25/94 modified 7/14/94
  6.  
  7.       Compatible with experimental strong type checking.
  8.  
  9.       This definition uses the assistance macros from gcoope10.h.
  10.  
  11. */
  12.  
  13. #define CLASS Dynmem
  14.  
  15. #include "gcoope10.h"
  16.  
  17. object CLASS;
  18.  
  19. extern object Pointer;
  20. extern object Unsigned;
  21.  
  22. USEGEN(reSize);
  23. USEGEN(sizeOf);
  24. USEGEN(valueOf);
  25. USEGEN(changeVal);
  26. USEGEN(addressOf);
  27.  
  28.  
  29. cmethod object m4New(object instance, unsigned short initSize)
  30. {
  31. void *       memArea;
  32.  
  33. if(NULL==makeInst(&instance)) return 0;
  34. memArea=s_malloc(initSize);
  35. g(New)(ST(Unsigned), initSize);
  36. g(New)(ST(Pointer),memArea);
  37. return instance;
  38. }
  39.  
  40.  
  41. imethod object m4reSize(object instance, unsigned short newSize)
  42. {
  43. void * memArea;
  44.  
  45. if(g(GEN(changeVal))(ST(Unsigned), newSize)) return FUNCFAIL;
  46. memArea=((VDPTRRV)g)(GEN(addressOf))(instance);
  47. memArea=s_realloc(memArea, newSize);
  48. return g(GEN(changeVal))(ST(Pointer), memArea);
  49. }
  50.  
  51.  
  52. cmethod object m4Kill(object instance)
  53. {
  54. void * memArea;
  55.  
  56. memArea=((VDPTRRV)g)(GEN(addressOf))(instance);
  57. s_free(memArea);
  58. g(Kill)(ST(Unsigned));
  59. g(Kill)(ST(Pointer));
  60. g(Kill)(Object, instance);
  61. return instance;
  62. }
  63.  
  64.  
  65.  
  66. CLASS_INSTALL
  67. {
  68. if(END==(CLASS=g(New)(Class, 0, 0, Pointer, Unsigned, END))) goto err;
  69. if(addGMthd(CLASS, New, (method) m4New)) goto err;
  70. if(addGMthd(CLASS, Kill, (method) m4Kill)) goto err;
  71. if(RMVGM(changeVal)) goto err;
  72. if(RMVGM(valueOf)) goto err;
  73. if(ADDGM(reSize)) goto err;
  74. if(RENGM(valueOf, Unsigned, sizeOf)) goto err;
  75. if(RENGM(valueOf, Pointer, addressOf)) goto err;
  76. return FUNCOKAY;
  77.  
  78. err:
  79. return FUNCFAIL;
  80. }
  81.  
  82.  
  83.  
  84.